<script setup>
import { ref, computed } from 'vue';

const count = ref(0);
const doubleCount = computed(() => count.value * 2);

function increment() {
  count.value++;
}

function decrement() {
  count.value--;
}

function reset() {
  count.value = 0;
}
</script>

<template>
  <div class="counter-container">
    <h2>计数器示例</h2>
    
    <div class="counter-display">
      <p class="count">{{ count }}</p>
      <p class="double-count">双倍值: {{ doubleCount }}</p>
    </div>
    
    <div class="counter-buttons">
      <button @click="decrement">-1</button>
      <button @click="reset">重置</button>
      <button @click="increment">+1</button>
    </div>
    
    <div class="counter-info">
      <p>这个组件展示了Vue的基本响应式特性:</p>
      <ul>
        <li>使用 <code>ref()</code> 创建响应式状态</li>
        <li>使用 <code>computed()</code> 创建计算属性</li>
        <li>使用事件处理更新状态</li>
      </ul>
    </div>
  </div>
</template>

<style scoped>
.counter-container {
  max-width: 500px;
  margin: 30px auto;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  background-color: #f9f9f9;
}

h2 {
  text-align: center;
  color: #2c3e50;
  margin-bottom: 20px;
}

.counter-display {
  text-align: center;
  margin-bottom: 20px;
}

.count {
  font-size: 48px;
  font-weight: bold;
  color: #42b983;
  margin: 0;
}

.double-count {
  font-size: 18px;
  color: #666;
  margin: 5px 0 0 0;
}

.counter-buttons {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-bottom: 20px;
}

.counter-buttons button {
  padding: 8px 16px;
  font-size: 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.counter-buttons button:first-child {
  background-color: #ff6b6b;
  color: white;
}

.counter-buttons button:nth-child(2) {
  background-color: #808080;
  color: white;
}

.counter-buttons button:last-child {
  background-color: #42b983;
  color: white;
}

.counter-buttons button:hover {
  opacity: 0.8;
  transform: scale(1.05);
}

.counter-info {
  background-color: #f0f0f0;
  padding: 15px;
  border-radius: 6px;
  font-size: 14px;
}

.counter-info code {
  background-color: #e8e8e8;
  padding: 2px 4px;
  border-radius: 3px;
  font-family: monospace;
}

.counter-info ul {
  margin: 10px 0 0 0;
  padding-left: 20px;
}
</style> 